
<div class="kpr-boxlet-grp">

  <a href="#" class="yg3e3739 btn btn-default">Back</a>

</div>

<div class="kpr-boxlet">

<div class="kb-title kb-underline">Access Keys</div>

<div id="q6p2le" class="alert hide"></div>

{{if .list}}

<table class="table table-hover kpr_font_fixspace">
  <thead>
    <tr>
      <th>Access Key</th>
      <th>Secret Key</th>
      <th>Created</th>
      <th>Status</th>
      <th>Operation</th>
    </tr>
  </thead>
  <tbody>
    {{range .list}}
    <tr>
      <td>{{.id}}</td>
      <td>{{.secret}}</td>
      <td>{{date .created}}</td>
      <td>
        {{if eq .status 1}}
        <span class="label label-success">{{.status_display}}</span>
        {{end}}
        {{if eq .status 0}}
        <span class="label label-default">{{.status_display}}</span>
        {{end}}
      </td>
      <td>
        {{if eq .status 1}}
        <a class="mtrcyaxx" href="#0,{{.id}}">Disable</a>
        {{end}}
        {{if eq .status 0}}
        <a class="mtrcyaxx" href="#1,{{.id}}">Active</a>
        {{end}}
      </td>
    </tr>
    {{end}}
  </tbody>
</table>


{{else}}
<div class="alert alert-info" style="margin:20px 0;">No Access Keys yet!</div>
{{end}}

<div>
<button type="button" 
  class="btn btn-primary btn-sm" 
  onclick="_kpr_bucket_accesskey_new()">
  New Access Key
</button>
</div>

</div>


<script type="text/javascript">

$(".yg3e3739").click(function() {
    _kpr_nav_go("bucket/list", "");
});

$(".mtrcyaxx").click(function() {
    
    var opt = $(this).attr("href").substr(1);
    var params = "keyid="+ opt.substr(2) +"&status="+ opt.substr(0,1);

    $.ajax({
        type    : "GET",
        url     : "/keeper/bucket/access-key-set?"+ params,
        timeout : 3000,
        success : function(rsp) {

            var rsj = JSON.parse(rsp);

            if (rsj.status == 200) {
                
                lessAlert("#q6p2le", 'alert-success', "Successfully updated");  

                window.setTimeout(function(){
                    keeperComLoader("bucket/access-keys?name={{.bucket_name}}");
                }, 1500);

            } else {
                lessAlert("#q6p2le", 'alert-danger', rsj.message);
            }
        },
        error: function(xhr, textStatus, error) {
            lessAlert("#q6p2le", 'alert-danger', '{{T . "Internal Server Error"}}');
        }
    });

    //
});

function _kpr_bucket_accesskey_new()
{
    $.ajax({
        type    : "GET",
        url     : "/keeper/bucket/access-key-new?bucket_name={{.bucket_name}}",
        timeout : 3000,
        success : function(rsp) {

            var rsj = JSON.parse(rsp);

            if (rsj.status == 200) {
                
                lessAlert("#q6p2le", 'alert-success', "Successfully created");  

                window.setTimeout(function(){
                    keeperComLoader("bucket/access-keys?name={{.bucket_name}}");
                }, 1500);

            } else {
                lessAlert("#q6p2le", 'alert-danger', rsj.message);
            }
        },
        error: function(xhr, textStatus, error) {
            lessAlert("#q6p2le", 'alert-danger', '{{T . "Internal Server Error"}}');
        }
    });
}

</script>
